﻿using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Optimization;

namespace NotesVaultOnline.Class.Helper
{
    public static class NovoHtmlHelper
    {
        /// <summary>
        /// Should match Scripts \ sub-folder
        /// </summary>
        public enum ScriptType
        {
            Partials,
            Pages
        }

        public static IHtmlString RenderCustomScript(this HtmlHelper helper, string scriptFile, ScriptType type)
        {
            //Work out bundles path
            string bundle = string.Format("~/Script/novo-{0}-{1}", type.ToString().ToLower(), scriptFile.ToLower().Substring(0, scriptFile.IndexOf('.')));
            //Work out virtual path
            string path = string.Format("~/Scripts/{0}/{1}", type.ToString(), scriptFile);

            //Add to bundle
            BundleTable.Bundles.Add(new ScriptBundle(bundle).Include(path));

            //Then render
            return Scripts.Render(bundle);
        }
    }
}